<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">

<head th:replace="common/head::head">
</head>

<body>
<div class="layui-container">
    <blockquote class="layui-elem-quote layui-quote-nm">
        分发文件是上传一个压缩包，并自动分发到对应节点，分发后的操作将在文件分发结束后自动执行
    </blockquote>
    <form action="upload" class="layui-form" style="margin-top: 20px">
        <div class="layui-form-item">
            <label class="layui-form-label">分发包</label>
            <div class="layui-input-inline">
                <button type="button" class="layui-btn" id="selectZip">
                    <i class="layui-icon">&#xe67c;</i>选择ZIP文件
                </button>
                <div class="layui-form-mid layui-word-aux" id="zipResult"></div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">清空发布</label>
                <div class="layui-input-block">
                    <input type="checkbox" value="true"
                           th:checked="${outGivingModel?.clearOld}"
                           name="clearOld"
                           lay-skin="switch"
                           lay-text="是|否">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">分发后</label>
            <div class="layui-input-block">
                <select name="afterOpt" id="afterOpt" required lay-verify="required">
                    <option value="">请选择分发后的操作</option>

                    <option th:each="item : ${afterOpt}" th:value="${item.code}"
                            th:selected="${item.code==outGivingModel.afterOpt}" th:text="${item.desc}">
                    </option>
                </select>
            </div>
        </div>

        <div class="layui-form-item" style="padding-left: 20%;padding-top: 20px;">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="form_outgiving">提交
            </button>
        </div>
    </form>
</div>

</body>


<script type="text/javascript">
    function loadSuccess() {
        var uploadConfig, hashSelectConfig, updateFormData;
        uploadRender({
            elem: '#selectZip',
            url: './upload',
            multiple: false,
            exts: 'tar|bz2|gz|zip|tar.bz2|tar.gz',
            acceptMime: '.tar,.bz2,.gz,.zip,.tar.bz2,.tar.gz',
            field: 'file',
            data: {
                afterOpt: function () {
                    return updateFormData.afterOpt;
                },
                clearOld: function () {
                    return updateFormData.clearOld
                },
                id: getQueryString("id")
            },
            auto: false,
            choose: function (obj) {
                hashSelectConfig = true;
                obj.preview(function (index, file, result) {
                    $("#zipResult").html("已选择:" + file.name);
                });
            },
            done: function (res) {
                layer.msg(res.msg);
                if (200 === res.code) {
                    autoClose();
                }
            }
        }, function (data) {
            uploadConfig = data;
        });

        form.on('submit(form_outgiving)', function (data) {
            updateFormData = data.field;
            if (!hashSelectConfig) {
                layer.msg("请选择分发包");
                return false;
            }
            uploadConfig.upload();
            return false;
        });
    }
</script>

</html>
